/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.facade.main.controller;

import com.alibaba.fastjson.JSONObject;
import com.facade.main.httpunit.HttpHelper;
import com.facade.main.httpunit.HttpProperty;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Administrator
 */
@RestController
public class ProductController {
    //更新库存，价格
    @RequestMapping(value = "/product/stock", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String productStock(@RequestBody JSONObject json){
        String url = String.format("%s/product/stock", HttpProperty.TESTURL);
        return HttpHelper.postData(url, json.toJSONString(), "");
    }
    
    //新增商品
    @RequestMapping(value = "/product/import", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String productImport(@RequestBody JSONObject json){
        String url = String.format("%s/product/import", HttpProperty.TESTURL);
        return HttpHelper.postData(url, json.toJSONString(), "");
    }
    
    //查询商品添加记录
    @RequestMapping(value = "/product/importsearch", method = RequestMethod.GET)
    public String productImportSearch(@RequestParam("batch_id") String batch_id){
        String querString = String.format("batch_id=%s",batch_id);
        String url = String.format("product/import??%s", HttpProperty.TESTURL, querString);
        return HttpHelper.getData(url,querString);
    }
    
    //删除商品
    @RequestMapping(value = "/product/delete", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
    public String productDelete(@RequestBody JSONObject json){
        String url = String.format("%s/product/delete", HttpProperty.TESTURL);
        return HttpHelper.postData(url, json.toJSONString(), "");
    }
    
    //查询门店商品
    @RequestMapping(value = "/product/search", method = RequestMethod.GET)
    public String productSearch(@RequestParam("erp_store_id")String erp_store_id, @RequestParam("page") String page,@RequestParam("per")String per){
        String querString = String.format("page=%s%per=%s", page, per);
        String url = String.format("%s/product/%s?%s", HttpProperty.TESTURL, erp_store_id, querString);
        return HttpHelper.getData(url,querString);
    }
}
